package com.jl.controller;

import com.jl.config.WeiXinSignUtil;
import com.jl.pojo.Jsapi;
import com.jl.util.AdvancedUtil;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Map;

@Controller
public class WebController {

    /**
     * 描述：跳转界面
     * author：yulin
     * Createa date 2020-2-12 11:25
     */
    @RequestMapping("index")
    public String text(){


        //用户授权

        //抓取用户的code
        //获取token
        //获取用户的详细信息（定义的实体WeiXinUser）
        //跳转界面

        return "index";


    }

    /**
     * @Description 调用微信jssdk（成功之后要打开的界面！）
     * @Creat date 2018-12-1
     * @author yulin
     * @return updatepicture.html
     */
    @RequestMapping("newIndex")
    public String updatepicture(Model model) {

        String jsapi_ticket =AdvancedUtil.getJSApi();
        String url="http://hyxw.work/text1";
        Map<String,String> map = AdvancedUtil.sign(jsapi_ticket, url);

        Jsapi jsapi=new Jsapi();

        jsapi.setTimestamp(map.get("timestamp"));
        jsapi.setNonceStr(map.get("nonceStr"));
        jsapi.setSignature(map.get("signature"));
        jsapi.setAppId(WeiXinSignUtil.appid);
        System.out.println(jsapi);
        model.addAttribute("jsapi",jsapi);

        return "index";
    }

}
